package com.globallogic.vacationplanner.model.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "project", catalog = "vacation_planner")
public class Project implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	private Integer idProject;
	private User user;
	private String name;
	private String description;
	private String state;
	private Set<User> memberedUsers = new HashSet<User>();

	public Project() {
	}

	public Project(User user, String name, String description, String state) {
		this.user = user;
		this.name = name;
		this.description = description;
		this.state = state;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_project", unique = true, nullable = false)
	public Integer getIdProject() {
		return this.idProject;
	}

	public void setIdProject(Integer idProject) {
		this.idProject = idProject;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_user", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "name", nullable = false, length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "description", nullable = false, length = 65535)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "state", nullable = false, length = 15)
	public String getState() {
		return this.state;
	}

	public void setState(String state) {
		this.state = state;
	}

	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "user_project", joinColumns = { @JoinColumn(name = "id_project") }, inverseJoinColumns = { @JoinColumn(name = "id_user") })
	public Set<User> getMemberedUsers() {
		return memberedUsers;
	}

	public void setMemberedUsers(Set<User> memberedUsers) {
		this.memberedUsers = memberedUsers;
	}
}
